$(function () {
	var url = sessionStorage.allUrl;
	var come=sessionStorage.comePro;
	if(url){
		if(come){
			
		}else{
			$("#proButtonT").hide();
			$("#proButtonT").parent().removeClass('col-md-offset-4').addClass('col-md-offset-3');
		}
	}else{
		$('#hotReturn').addClass('hide');
	} 
	var params={};
	padMarketing.ajaxNormal('/pad_marketing/main/type005pkgGetHotList.action', params,
			function(data) {	
		//console.log(data);
		var arr= JSON.parse(data.pkgGetHotList);
		for(var i in arr){
			if(112==arr[i].pkgId){
				$('#title').attr('datas',JSON.stringify(arr[i]));	
				break;
			}
		}
		var star = "";
		//console.log(arr);
		/*var newarr = arr.slice(1, 2);
		console.log(newarr);*/
		/*for(var i = 0;i < arr.length; i++){
			if(arr[i].pkgId == '109'){
				arr.splice(1, 1, arr[i]);
				arr.splice(i, 1, newarr[0]);
			}
			
		}*/
		for(var i = 0; i < arr.length; i++) {
			$('.swiper-slide').eq(i).find(".buy").html();
			var img = $('<div data=\''+JSON.stringify(arr[i])+'\' class="swiper-slide" onClick="showDiv(' + "'open1'" + ')"><img src="/portal/resources/images/product/packages/'+ arr[i].pkgId  +'/RM.jpg"><h4 class="lh-30 font-18 p-overflow">' + arr[i].title + '</h4><p class="buy" class="lh-30 font-14 gray">'+arr[i].subTitle+'</p><br /></div>');
			$('.banner').append(img);			
			star="";								
			for(var j = 0; j < arr[i].stars; j++) {				
				star += '<span class=\"icon icon-star\"></span>';				
			}
			$('.swiper-slide').eq(i).find(".buy").after(star);
			
		}
			
		$(".featured").swiperProduct();	
		/*var slide = $(".swiper-slide-active").next().attr('data');		
		var obj = JSON.parse(slide);
		//console.log(obj);
		//console.log(obj.allowSaling);
		$('.quickPay').attr('disabled','');
		$('.advices').attr('disabled','');
		if(obj.allowSaling){		
			$('.quickPay').attr('disabled',false);
			$('.advices').attr('disabled',false);
		}else{
			$('.quickPay').attr('disabled',true);
			$('.advices').attr('disabled',true);
		}*/
		sessionStorage.setItem('returnUrl', '/pad_marketing/main/type005pkgGetHot.action');
			}, function(data) {
				alertMsg('失败',1);
			},false);
	
	//出生日期
	var opt = {
        preset: 'date', //日期
        theme: 'android-ics light', //皮肤样式
        display: 'bottom', //显示方式 
        mode: 'scroller', //日期选择模式
        lang: 'zh',
        dateFormat: 'yy-mm-dd', // 日期格式
        setText: '确定', //确认按钮名称
        cancelText: '取消',//取消按钮名籍我
        dateOrder: 'yymmdd', //面板中日期排列格式
        dayText: '', monthText: '', yearText: '', //面板中年月日文字
        endYear:2020, //结束年份
        onSelect:function(valueText, inst){
        	//console.log(valueText);
        	$(this).next().val(valueText);
        	OnDateOfBirthChange(valueText,this);
        }
	};
	$('.input-group-addon').mobiscroll(opt);
/*	$('.input-group input:first').change(function(){
		$(this).parent().find('input:last').val(null);
		$('.input-group-addon').mobiscroll('setDate',new Date());
	});*/
});
//swiper-container featured
/*$(document).on('touchend',".banner",function(){
	var slide = $(".swiper-slide-active").next().attr('data');		
	var obj = JSON.parse(slide);
	console.log(obj);
	console.log(obj.allowSaling);
	$('.quickPay').attr('disabled','');
	$('.advices').attr('disabled','');
	if(obj.allowSaling){		
		$('.quickPay').attr('disabled',false);
		$('.advices').attr('disabled',false);
	}else{
		$('.quickPay').attr('disabled',true);
		$('.advices').attr('disabled',true);
	}
	});*/


$("#sureView").click(function(){	
	if($('#open1').css('display') == 'none'){
		var slide = $(".swiper-slide-active").next().attr('data');		
		var div = JSON.parse(slide);
		var pkgs = [];
		pkgs.push(div);		
	}else if($('#open1').css('display') == 'block'){
		var div = JSON.parse($('#title').attr("datas"));
		var pkgs =[];
		pkgs.push(div);
	}
	//清空三要素
	var dataOfBirth = $("#dataOfBirth").val();
	var  career     =$('input[id^=mobiscroll]').eq(0).val();
	if(dataOfBirth==""||career==""){
		alertMsg("请完整填写数据");
		return;
	}		
	closeDiv("open2");
	$('#popupLayerScreenLocker').css('display','none');
		
	    saveCp3MinData(this,pkgs);			
});

//建议书三要素创建
$('#surePro').click(function(){	
	if($('#open1').css('display') == 'none'){
		var slide = $(".swiper-slide-active").next().attr('data');
		var div = JSON.parse(slide);
		var pkgs = [];
		pkgs.push(div);		
	}else if($('#open1').css('display') == 'block'){
		var div = JSON.parse($('#title').attr("datas"));
		var pkgs =[];
		pkgs.push(div);
	}
	var age = $("#inputAge").val();
	var re = /^\d*$/;
	/*if(!re.test(age)||age==""||age==null){
		alertMsg("请正确输入年龄");
		return;
	}*/
	var flag = alt(open3);	
	 if(flag){
		 closeDiv("open3");
		$('#popupLayerScreenLocker').css('display','none');
	 }else{
		 alertMsg('请输入完整信息');
		 return;
	 }
	    quoCreate(this,pkgs);
});
//flag是立即购买 flag=1是滑动的  flag2是立即购买和建议书
function checkGood(flag,flag2){
	var result = true;
	//滑动的产品
	var slide = $(".swiper-slide-active").next().attr('data');
	var obj = JSON.parse(slide);	
	//产品详情的产品
	var ob ;
	var objParse = $('#title').attr("datas");
	if(objParse!=null && objParse!=""){
		ob = JSON.parse($('#title').attr("datas"));
	}
	if(flag==1){
		if(!obj.allowSaling){
			alertMsg("该产品暂不能购买");
			return;
		}
	}
	if(flag==2){
		if(!ob.allowSaling){		
			alertMsg('此产品不可购买');	
			return;
		}
	}
	//在判断打开什么  立即购买
	if(flag2==1){
		$("#normalSure").removeAttr("index");
		$("#normalSure").attr("index",2);
		showDiv('open2');
		
	}
	if(flag2==2){
		$("#normalSure").removeAttr("index");
		$("#normalSure").attr("index",3);
		showDiv('open3');
	}
}

function returnHref(){
	var url = sessionStorage.allUrl;
	sessionStorage.removeItem("allUrl");
	sessionStorage.removeItem("comePro");
	if(url){
		location.href=url;
		return;
	}
	location.href="/pad_marketing/index/index.action";
}





function returnHre(){	
	sessionStorage.removeItem("allUrl");
	sessionStorage.removeItem("comePro");
	location.href="/pad_marketing/index/index.action";
}